package com.sinosoft.front;

import java.net.MalformedURLException;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.apache.log4j.Logger;

import com.hangxin.basic.util.MyTimeUtil;
import com.sinosoft.front.dto.PremiumCaculateService.out.xsd.Applicant;
import com.sinosoft.front.dto.PremiumCaculateService.out.xsd.BzRelationMain;
import com.sinosoft.front.dto.PremiumCaculateService.out.xsd.CarInfo;
import com.sinosoft.front.dto.PremiumCaculateService.out.xsd.CarShipTaxInfo;
import com.sinosoft.front.dto.PremiumCaculateService.out.xsd.CombosData;
import com.sinosoft.front.dto.PremiumCaculateService.out.xsd.InsuredData;
import com.sinosoft.front.dto.PremiumCaculateService.out.xsd.ItemKindData;
import com.sinosoft.front.dto.PremiumCaculateService.out.xsd.Main;
import com.sinosoft.front.dto.common.xsd.TxInsuranceRequestEhm;
import com.sinosoft.front.dto.common.xsd.TxInsuranceRequestExtensionEhm;
import com.sinosoft.front.dto.xsd.PremiumCaculateRequest;
import com.sinosoft.front.dto.xsd.PremiumCaculateResponse;
import com.sinosoft.front.service.PremiumCaculateServicePortType;
import com.sinosoft.front.service.PremiumCaculateServicePortTypeProxy;

public class PremiumCaculateTest {

	static Logger logger = Logger.getLogger(VehicleModelQueryTest.class);
	public static void main(String[] args) throws RemoteException,
			ServiceException, MalformedURLException {

		// 调用服务器端方法 保费计算服务

		PremiumCaculateServicePortTypeProxy proxy = new PremiumCaculateServicePortTypeProxy();
		proxy.setEndpoint("http://proxy.tuxing51.com/frontServiceCenter/services/PremiumCaculateService?wsdl");
		PremiumCaculateServicePortType portType = proxy
				.getPremiumCaculateServicePortType();
		logger.info("============保费计算服务============");
		// 请求头信息
		PremiumCaculateRequest request = new PremiumCaculateRequest();
		TxInsuranceRequestEhm requestEhm = new TxInsuranceRequestEhm();
		requestEhm.setTransExeDate(MyTimeUtil.getCurrentDate());// 交易日期
		requestEhm.setTransExeTime(MyTimeUtil.getCurrentTime());// 交易时间
		request.setTxInsuranceRequestEhm(requestEhm);

		// requestEhm.setIinsuranceExtensionEhm(new IinsuranceExtensionEhm());

		// 请求扩展数据
		TxInsuranceRequestExtensionEhm extensionEhm = new TxInsuranceRequestExtensionEhm();
		extensionEhm.setOperator("HN1_Test");// 用户名
		extensionEhm.setOperatorKey("123456");// 密码
		request.setTxInsuranceRequestExtensionEhm(extensionEhm);
		logger.info("输入信息：");
		
		// Main主信息表
		Main main = new Main();
		main.setPolicySort("HN1");// 系统来源
		main.setFranchiserCode("4105979018");// 经销商代码
		main.setTotalAmount("75106.00");//投险总保额  车损险保额应等于车辆实际价值！
		main.setRelationFlag("2");// 是否关联 1-关联单、2-单商业、3-单交强
		main.setClassCode("05");// 险类标识 默认值05
		main.setBusinessNature("2");// 业务来源 2代表 专业代理
		main.setAgentCode("410511198203181755");// 代理人代码
		main.setStartDate("2017-04-23");// 起保时间
		main.setStartHour("0");
		main.setEndDate("2018-04-22");
		main.setEndHour("24");
		main.setPlatReturnMessage("2");
		main.setInputDate(String.valueOf(new java.sql.Date(System
				.currentTimeMillis())));//录单日期
		main.setOperateDate(String.valueOf(new java.sql.Date(System
				.currentTimeMillis())));//
		main.setCityAreaCode("410500");// 城市代码 安阳
		//main.setBusCheckCode("A");//商业险校验码
		//main.setBzCheckCode("C");//交强险校验码
		request.setMain(main);
		logger.info("Main主信息表:"+request.getMain());
		// Applicant投保人信息
		Applicant applicant = new Applicant();
		//applicant.setAppliCode("不知道");
		applicant.setAppliName("吴静菡");//投保人姓名
		applicant.setInsuredType("1");//关系人类型 1个人/2单位客户
		applicant.setIdentifyType("01");//证件类型
		applicant.setIdentifyNumber("410725199412015720");//证件号
		request.setApplicant(applicant);
		logger.info("投保人信息：");
		logger.info("投保人姓名:"+applicant.getAccountName()+
				",关系人类型:"+applicant.getInsuredType()+",证件类型:"+applicant.getIdentifyType()+
				",证件号:"+applicant.getIdentifyNumber());	
		// InsuredData对象详细信息
		InsuredData insuredData = new InsuredData();
		insuredData.setInsuredNature("3");//客户性质 3-自然人 4-法人标志
		insuredData.setInsuredType("1");//关系人类型  1个人/2单位客户
		insuredData.setIdentifyType("01");//证件类型
		insuredData.setIdentifyNumber("410725199412015720");//证件号
		insuredData.setSex("0");//性别 男
		insuredData.setAge(23);//年龄
		
		
		
		
		
		
		insuredData.setInsuredFlag("5");//被保险人标识位 1-被保险人 2-投保人 5-车主
		request.setInsuredDataArr(new InsuredData[] { insuredData });
		logger.info("InsuredData对象详细信息：");
		logger.info("关系人类型："+insuredData.getInsuredType());
		logger.info("证件类型："+insuredData.getIdentifyType());
		logger.info("证件号："+insuredData.getIdentifyNumber());
		logger.info("性别："+insuredData.getSex());
		logger.info("年龄："+insuredData.getAge());
		logger.info("标志："+insuredData.getInsuredFlag());

		// CarInfo车辆信息
		CarInfo carInfo = new CarInfo();
		carInfo.setActualValue("75106.00");//车辆实际价值
		carInfo.setAreaCode("04");//车辆行驶区域
		carInfo.setAreaName("中国境内(不含港澳台)");//行驶区域名称
		carInfo.setStandardName("大众汽车SVW71411HR轿车");//车型名称
		carInfo.setCarInsureRelation("1");//车辆所有关系
		carInfo.setCarKindCode("A0");//车辆种类
		carInfo.setCarType("K33");//行驶证车辆类型
		carInfo.setColorCode("99");//车身颜色
		carInfo.setCompleteKerbMass(0);//整备质量
		carInfo.setEngineNo("149357");//发动机号
		carInfo.setEnrollDate("2016-05-11");//初次登记日期
		carInfo.setExhaustScale(1.395);//排量
		carInfo.setFrameNo("LSVGY26R0F2159877");//车架号
		carInfo.setImportFlag("C");//产地种类
		carInfo.setLicenseNo("豫GSD122");//车牌号码
		carInfo.setLicenseType("02");//号牌种类代码
		carInfo.setLicenseColorCode("01");//号牌底色
		carInfo.setPurchasePrice(79900.00);//新车购置价
		carInfo.setModelCode("DZAAKD0152");//车型代码
		carInfo.setSeatCount(5);//核定载客
		carInfo.setTonCount(0.0);//核定载质量
		carInfo.setUseNatureCode("8A");//使用性质
		carInfo.setUseYears(2);//车龄?
		carInfo.setVin("LSVGY26R0F2159877");//VIN码
		carInfo.setFuleType("0");//燃料种类?
		carInfo.setCertifyDate("2016-05-11");//发证日期
		carInfo.setVehicleStyleDesc("小型普通客车");//车辆类型描述
		carInfo.setPlatmodelCode("BSHCBMUC0027");//行业车型编码
		carInfo.setPlatmodelname("大众汽车SVW71411HR 舒适版");//行业车型名称
		carInfo.setCarBuyDate("2016-05-10");//购买日期?
		carInfo.setCarPriceType("1");//车辆价值确定方式
		request.setCarInfo(carInfo);
		logger.info("车辆信息：");
		logger.info("车辆实际价值："+carInfo.getActualValue());
		logger.info("车辆行驶区域："+carInfo.getAreaCode());
		logger.info("行驶区域名称："+carInfo.getAreaName());
		logger.info("车型名称："+carInfo.getStandardName());
		logger.info("车辆所有关系："+carInfo.getCarInsureRelation());
		logger.info("车辆种类："+carInfo.getCarKindCode());
		logger.info("行驶证车辆类型："+carInfo.getCarType());
		logger.info("车身颜色："+carInfo.getColorCode());
		logger.info("整备质量："+carInfo.getCompleteKerbMass());
		logger.info("发动机号："+carInfo.getEngineNo());
		logger.info("初次登记日期："+carInfo.getEnrollDate());
		logger.info("排量："+carInfo.getExhaustScale());
		logger.info("车架号："+carInfo.getFrameNo());
		logger.info("产地种类："+carInfo.getImportFlag());
		logger.info("车牌号码："+carInfo.getLicenseNo());
		logger.info("号牌种类代码："+carInfo.getLicenseType());
		logger.info("号牌底色："+carInfo.getLicenseColorCode());
		logger.info("新车购置价："+carInfo.getPurchasePrice());
		logger.info("车型代码："+carInfo.getModelCode());
		logger.info("核定载客："+carInfo.getSeatCount());
		logger.info("核定载质量："+carInfo.getTonCount());
		logger.info("使用性质："+carInfo.getUseNatureCode());
		logger.info("车龄?："+carInfo.getUseYears());
		logger.info("VIN码："+carInfo.getVin());
		logger.info("燃料种类?："+carInfo.getFuleType());
		logger.info("发证日期："+carInfo.getCertifyDate());
		logger.info("车辆类型描述："+carInfo.getVehicleStyleDesc());
		logger.info("行业车型编码："+carInfo.getPlatmodelCode());
		logger.info("行业车型名称："+carInfo.getPlatmodelname());
		logger.info("购买日期?："+carInfo.getCarBuyDate());
		logger.info("车辆价值确定方式："+carInfo.getCarPriceType());

		// CarDriverData对象详细信息
//		CarDriverData carDriverData = new CarDriverData();
//		carDriverData.setDriverName("申辉");//姓名
//		carDriverData.setIdentifyNumber("驾驶证号码");//驾驶证号码
//		carDriverData.setAcceptLicenseDate("2016-09-21");//初次领证日期
//		// carDriverData.setTaxFlag("")
//		request.setCarDriverDataArr(new CarDriverData[] { carDriverData });
//		logger.info("CarDriverData对象详细信息:"+request.getCarDriverDataArr());
		// CarShipTaxInfo车船税
		CarShipTaxInfo carShipTaxInfo = new CarShipTaxInfo();
		carShipTaxInfo.setTaxFlag("1N");//车船税标志
		carShipTaxInfo.setTaxPayerName("吴静菡");//纳税人姓名
		//carShipTaxInfo.setTaxPayerName("申辉");
		request.setCarShipTaxInfo(carShipTaxInfo);
		logger.info("车船税:"+request.getCarShipTaxInfo());
		logger.info("车船税标志:"+carShipTaxInfo.getTaxFlag());
		logger.info("纳税人姓名:"+carShipTaxInfo.getTaxPayerName());
		
		// CombosDataArr自选及套餐类型
		// CombosData对象详细信息
		CombosData combosData = new CombosData();
		combosData.setRiskCode("0511");//险种代码
		// combosData.setItemKindArr
		// EngageDataArr特约信息
		logger.info("险种代码:"+combosData.getRiskCode());
		// ItemKindArr险别信息
		ItemKindData itemKindData = new ItemKindData();
		itemKindData.setAmount(75106.00);//保险金额/赔偿限额
		itemKindData.setStartDate("2017-04-28");//保险起期
		itemKindData.setEndDate("2018-04-27");//保险止期
		itemKindData.setDeductableFlag("1");//是否投保不计免赔 0-否 1-是
		itemKindData.setKindCode("001");//险别代码 商业险
		itemKindData.setKindName("机动车损失保险");//险别名称
		/*itemKindData.setKindCode("301");//险别代码 商业险
		itemKindData.setKindName("不计免赔率险（机动车损失保险）");//险别名称
*/		itemKindData.setRiskCode("0511");//险种代码
		

		
		ItemKindData itemKindData1 = new ItemKindData();
		//itemKindData1.setAmount(75106.00);//保险金额/赔偿限额
		itemKindData1.setStartDate("2017-03-24");//保险起期
		itemKindData1.setEndDate("2018-03-23");//保险止期
		itemKindData1.setDeductableFlag("0");//是否投保不计免赔 0-否 1-是
		/*itemKindData1.setKindCode("002");//险别代码 商业险
		itemKindData1.setKindName("第三者责任保险");//险别名称
*/		itemKindData1.setKindCode("301");//险别代码 商业险
		itemKindData1.setKindName("不计免赔率险（机动车损失保险）");//险别名称
		itemKindData1.setRiskCode("0511");//险种代码
		/*ItemKindData itemKindData2 = new ItemKindData();
		itemKindData2.setAmount(75106.00);//保险金额/赔偿限额
		itemKindData2.setStartDate("2017-03-24");//保险起期
		itemKindData2.setEndDate("2018-03-23");//保险止期
		itemKindData2.setDeductableFlag("0");//是否投保不计免赔 0-否 1-是
		itemKindData2.setKindCode("007");//险别代码 商业险
		itemKindData2.setKindName("全车盗抢保险");//险别名称
		itemKindData2.setKindCode("306");//险别代码 商业险
		itemKindData2.setKindName("不计免赔率险（全车盗抢保险）");//险别名称
		itemKindData2.setRiskCode("0511");//险种代码
*/		
		combosData.setItemKindArr(new ItemKindData[] { itemKindData,itemKindData1 });
		request.setCombosDataArr(new CombosData[] { combosData });
		
		logger.info("CombosDataArr自选及套餐类型:"+request.getCombosDataArr(0).getItemKindArr());
		logger.info("保险金额/赔偿限额："+itemKindData.getAmount());
		logger.info("保险起期："+itemKindData.getStartDate());
		logger.info("保险止期："+itemKindData.getEndDate());
		logger.info("是否投保不计免赔 0-否 1-是："+itemKindData.getDeductableFlag());
		logger.info("险别代码 商业险："+itemKindData.getKindCode());
		logger.info("险别名称："+itemKindData.getKindName());
		logger.info("险种代码："+itemKindData.getRiskCode());
		
//		logger.info("险别信息:"+request.getCombosDataArr(0).getItemKindArr(1));
		logger.info("保险金额："+itemKindData1.getAmount());
		logger.info("保险起期："+itemKindData1.getStartDate());
		logger.info("保险止期："+itemKindData1.getEndDate());
		logger.info("是否投保不计免赔 0-否 1-是："+itemKindData1.getDeductableFlag());
		logger.info("险别代码 商业险："+itemKindData1.getKindCode());
		logger.info("险别名称："+itemKindData1.getKindName());
		logger.info("险种代码："+itemKindData1.getRiskCode());
//
//		// 1.7.1.16. BzRelationMain关联交强险基础信息
		BzRelationMain bzRelationMain = new BzRelationMain();
		bzRelationMain.setStartDate_bz("2017-03-24");
		bzRelationMain.setEndDate_bz("2018-03-23");
		bzRelationMain.setStartHour_bz("0");
		bzRelationMain.setEndHour_bz("24");

		request.setBzRelationMain(bzRelationMain);
		logger.info("关联交强险基础信息:"+request.getBzRelationMain());
		logger.info("交强险起期："+bzRelationMain.getStartDate_bz());
		logger.info("交强险止期："+bzRelationMain.getEndDate_bz());
		logger.info("交强险起保小时："+bzRelationMain.getStartHour_bz());
		logger.info("交强险终保小时："+bzRelationMain.getEndHour_bz());
		
		logger.info("返回内容：");
//ModelCode
		PremiumCaculateResponse response = portType.premiumCaculate(request);
		System.out.println(response.getTxInsuranceResponseEhm()
				.getTransResultEhm().getResultCode());
		
		System.out.println("errorNo:"+response.getTxInsuranceResponseEhm()
				.getTransResultEhm().getErrorNo());
		
		System.out.println(response.getTxInsuranceResponseEhm()
				.getTransResultEhm().getResultInfoDesc());
		System.out.println(response.getTxInsuranceResponseEhm()
				.getTransResultEhm().getErrorNo());//SsProposalNo

		
		System.out.println(response.getMain().getSsProposalNo());
		System.out.println("商业险平台返回信息"+response.getMain().getPlatReturnMessage());
		//System.out.println(response.getMain().getPlatformICRemark());


		System.out.println("试算单号:"+response.getMain().getSsProposalNo());
		System.out.println("商业险校验码:"+response.getMain().getBusCheckCode());
		System.out.println("交强险校验码:"+response.getMain().getBzCheckCode());
		//System.out.println(""+request.getMain());

		// 获取返回信息
		logger.info("返回码："+response.getTxInsuranceResponseEhm().getTransResultEhm().getResultCode());
		logger.info("返回内容："+response.getTxInsuranceResponseEhm()
				.getTransResultEhm().getResultInfoDesc());
		logger.info("返回错误码："+response.getTxInsuranceResponseEhm()
				.getTransResultEhm().getErrorNo());
		logger.info("返回Main对象详细信息："+response.getMain());
		
		logger.info("ItemKindArr险别信息："+response.getCombosDataArr(0).getItemKindArr());
		logger.info("保险金额/赔偿限额："+response.getCombosDataArr(0).getItemKindArr(0).getAmount());
		logger.info("保险起期："+response.getCombosDataArr(0).getItemKindArr(0).getStartDate());
		logger.info("保险止期："+response.getCombosDataArr(0).getItemKindArr(0).getEndDate());
		logger.info("是否投保不计免赔 0-否 1-是："+response.getCombosDataArr(0).getItemKindArr(0).getDeductableFlag());
		logger.info("险别代码 商业险："+response.getCombosDataArr(0).getItemKindArr(0).getKindCode());
		logger.info("险别名称："+response.getCombosDataArr(0).getItemKindArr(0).getKindName());
		logger.info("险种代码："+response.getCombosDataArr(0).getItemKindArr(0).getRiskCode());
		
		//logger.info("ItemKindData对象详细信息："+response.getCombosDataArr(0).getItemKindArr(1));
		logger.info("保险金额："+response.getCombosDataArr(0).getItemKindArr(1).getAmount());
		logger.info("保险起期："+response.getCombosDataArr(0).getItemKindArr(1).getStartDate());
		logger.info("保险止期："+response.getCombosDataArr(0).getItemKindArr(1).getEndDate());
		logger.info("是否投保不计免赔 0-否 1-是："+response.getCombosDataArr(0).getItemKindArr(1).getDeductableFlag());
		logger.info("险别代码 商业险："+response.getCombosDataArr(0).getItemKindArr(1).getKindCode());
		logger.info("险别名称："+response.getCombosDataArr(0).getItemKindArr(1).getKindName());
		logger.info("险种代码："+response.getCombosDataArr(0).getItemKindArr(1).getRiskCode());
		
		logger.info("车辆信息："+response.getCarInfo());
		logger.info("车辆实际价值："+response.getCarInfo().getActualValue());
		logger.info("车辆行驶区域："+response.getCarInfo().getAreaCode());
		logger.info("行驶区域名称："+response.getCarInfo().getAreaName());
		logger.info("车型名称："+response.getCarInfo().getStandardName());
		logger.info("车辆所有关系："+response.getCarInfo().getCarInsureRelation());
		logger.info("车辆种类："+response.getCarInfo().getCarKindCode());
		logger.info("行驶证车辆类型："+response.getCarInfo().getCarType());
		logger.info("车身颜色："+response.getCarInfo().getColorCode());
		logger.info("整备质量："+response.getCarInfo().getCompleteKerbMass());
		logger.info("发动机号："+response.getCarInfo().getEngineNo());
		logger.info("初次登记日期："+response.getCarInfo().getEnrollDate());
		logger.info("排量："+response.getCarInfo().getExhaustScale());
		logger.info("车架号："+response.getCarInfo().getFrameNo());
		logger.info("产地种类："+response.getCarInfo().getImportFlag());
		logger.info("车牌号码："+response.getCarInfo().getLicenseNo());
		logger.info("号牌种类代码："+response.getCarInfo().getLicenseType());
		logger.info("号牌底色："+response.getCarInfo().getLicenseColorCode());
		logger.info("新车购置价："+response.getCarInfo().getPurchasePrice());
		logger.info("车型代码："+response.getCarInfo().getModelCode());
		logger.info("核定载客："+response.getCarInfo().getSeatCount());
		logger.info("核定载质量："+response.getCarInfo().getTonCount());
		logger.info("使用性质："+response.getCarInfo().getUseNatureCode());
		logger.info("车龄："+response.getCarInfo().getUseYears());
		logger.info("VIN码："+response.getCarInfo().getVin());
		logger.info("燃料种类："+response.getCarInfo().getFuleType());
		logger.info("车辆类型描述："+response.getCarInfo().getVehicleStyleDesc());
		logger.info("行业车型编码："+response.getCarInfo().getPlatmodelCode());
		logger.info("行业车型名称："+response.getCarInfo().getPlatmodelname());
		logger.info("购买日期："+response.getCarInfo().getCarBuyDate());
		logger.info("市场公允价值："+response.getCarInfo().getFairMarketValue());
		logger.info("车辆价值确定方式："+response.getCarInfo().getCarPriceType());
		
		logger.info("车船税：");
//		logger.info("车船税标志："+response.getCarShipTaxInfo().getTaxFlag());//有问题
//		logger.info("纳税人姓名："+response.getCarShipTaxInfo().getTaxPayerName());//有问题
		
		
		logger.info("特约信息：");
		logger.info("特别约定信息："+response.getCombosDataArr());
		
		logger.info("EngageData对象详细信息："+response.getCombosDataArr(0).getEngageDataArr());
//		logger.info("险种代码："+response.getCombosDataArr(0).getEngageDataArr(0).getRiskCode());//有问题

		
		logger.info("CombosDataArr自选及套餐类型："+response.getCombosDataArr());
		logger.info("序号："+response.getCombosDataArr(0).getSerialNo());
		logger.info("险种代码："+response.getCombosDataArr(0).getRiskCode());
		logger.info("险别信息："+response.getCombosDataArr(0).getItemKindArr());
		
		logger.info("-------------------------------------------");
		System.out.println("baofei:"+response.getCombosDataArr(0).getItemKindArr(0).getBenchMarkPremium());
	}

}
